﻿using Microsoft.Office.Tools.Ribbon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace WordRegexAddIn
{
    public partial class RegexRibbon
    {

        private RegexFinder finder;

        private void RegexRibbon_Load(object sender, RibbonUIEventArgs e)
        {
            finder = new RegexFinder(Globals.ThisAddIn.Application);
            
        }

        

        private void btnFind_Click(object sender, RibbonControlEventArgs e)
        {
            finder.Find(editRegex.Text);
        }

        private void checkIgnoreCase_Click(object sender, RibbonControlEventArgs e)
        {
            if (checkIgnoreCase.Checked)
            {
                finder.Options |=  RegexOptions.IgnoreCase;
            }
            else
            {
                finder.Options &= ~RegexOptions.IgnoreCase;
            }

        }

        private void btnFindPrev_Click(object sender, RibbonControlEventArgs e)
        {
            finder.Previous(editRegex.Text);
        }

        private void btnReplace_Click(object sender, RibbonControlEventArgs e)
        {
            finder.Replace(editRegex.Text, editReplace.Text);
        }

        private void btnReplaceAll_Click(object sender, RibbonControlEventArgs e)
        {
            finder.ReplaceAll(editRegex.Text, editReplace.Text);
        }

        private void btnHelp_Click(object sender, RibbonControlEventArgs e)
        {
            System.Diagnostics.Process.Start("https://gitee.com/fldx/WordRegexAddIn");
        }

        private void btnUpdate_Click(object sender, RibbonControlEventArgs e)
        {
            System.Diagnostics.Process.Start("https://gitee.com/fldx/WordRegexAddIn/releases");
        }

        private void group1_DialogLauncherClick(object sender, RibbonControlEventArgs e)
        {

        }
    }
}
